package com.googlecode.lookie.platform.totd;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.richclient.command.support.ApplicationWindowAwareCommand;
import org.springframework.richclient.settings.Settings;

import com.googlecode.lookie.platform.settings.LookieSettingsManager;
import com.googlecode.lookie.platform.settings.SettingsIds;

public class TipOfTheDayCommand
    extends ApplicationWindowAwareCommand
    implements ApplicationContextAware
{

    private TipOfTheDayBox tipOfTheDayBox;

    private LookieSettingsManager settingsManager;

    public TipOfTheDayCommand()
    {
        super( "tipOfTheDayCommand" );
    }

    public void setTipOfTheDayBox( TipOfTheDayBox tipOfTheDayBox )
    {
        this.tipOfTheDayBox = tipOfTheDayBox;
    }

    public void setSettingsManager( LookieSettingsManager settingsManager )
    {
        this.settingsManager = settingsManager;
    }

    @Override
    protected void doExecuteCommand()
    {
        Settings userSettings = settingsManager.getUserSettings();
        boolean showTips = userSettings.getBoolean( SettingsIds.SHOW_TIPS );

        tipOfTheDayBox.setShowTipsSelected( showTips );
        tipOfTheDayBox.display( getApplicationWindow().getControl() );
        showTips = tipOfTheDayBox.isShowTipsSelected();
        userSettings.setBoolean( SettingsIds.SHOW_TIPS, showTips );
    }

    public void setApplicationContext( ApplicationContext applicationContext )
        throws BeansException
    {
        // TODO Auto-generated method stub

    }

}
